home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk180 / arexxtutorial / archie18 / equal.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-19  |  4KB  |  145 lines

  1. /* equalize.rexx -- a utility for Archie by Christian '<CB>' Balzer
  2.  
  3. --  _  _
  4.  / /  | \ \  <CB> aka Christian Balzer  - The Software Brewery -
  5. < <   |-<  > UUCP: decwrl!frambo.dec.com!cb OR cb@frambo.dec.com
  6.  \ \_ |_/ /  CIS : 71001,210 (be brief!) | Phone: +49 6150 4151 (CET!)
  7. ------------ Mail: Im Wingertsberg 45, D-6108 Weiterstadt, F.R.G.
  8.  
  9. Usage: [rx] equalize SOURCE DESTINATION [-options]
  10.  
  11. SOURCE and DESTINATION are valid AmigaDOS path's WITHOUT trailing
  12. slashes '/'.
  13. Valid options are: -p   This option will only print the differing
  14.                         filenames, but not delete them. Use it to
  15.                         see if you aren't about to destroy your work!
  16.  
  17. Equalize will scan all files at SOURCE and it's subdirectories and
  18. compare them to the files at DESTINATION and the corresponding
  19. subdirectories. ALL files at DESTINATION that can't be found in
  20. SOURCE will be DELETED!!! This goes for directory trees, too!!!
  21.  
  22. WARNING!!! Use this beast only when you know what you're doing! :-)
  23.  
  24. BTW, the name of this utility wasn't inspired by the TV series
  25. "The Equalizer". Or was it? :-)
  26.  
  27. In this version, filenames or directories containing blanks
  28. (like "My Dir:My File"), are NOT supported!  */
  29.  
  30. /* This is Public Domain, read the source and learn */
  31.  
  32. say 'Equalize 1.3 (09-Feb-89) by <CB>'
  33.  
  34. /* open the Rexx support library */
  35.  
  36. if ~show('L',"rexxsupport.library") then do
  37.    if addlib('rexxsupport.library',0,-30,0) then
  38.       say 'added rexxsupport.library'
  39.    else do;
  40.       say 'support library not available'
  41.       exit 10
  42.       end
  43.    end
  44.  
  45. address command
  46. call pragma 'priority',-1
  47.  
  48. arg rein
  49.  
  50. /* The parser */
  51. copt = 'clone'
  52.  
  53. if words(rein) < 2 then do
  54.         say 'Come on, gimme a SOURCE *AND* a DESTINATION path'
  55.         say 'Ya better try again... Bye!'
  56.         exit 10
  57. end
  58.  
  59.  
  60. root = subword(rein,1,1)
  61. dest = subword(rein,2,1)
  62. dstat = 1
  63.  
  64. if ~ exists(root) then do
  65.         say 'Source not found'
  66.         say 'Exiting... Check your parameters'
  67.         exit 10
  68. end
  69.  
  70. if ~ exists(dest) then do
  71.         say 'Destination not found'
  72.         say 'Exiting... Check your parameters'
  73.         exit 15
  74. end
  75.  
  76. if words(rein) > 2 then do
  77.         if subword(rein,3,1) = '-P' then
  78.                 dstat = 0
  79. end
  80.  
  81. if right(root,1) ~= ':' then
  82.   root = root || '/'
  83. if root = '/' then root = ''
  84.  
  85. if right(dest,1) ~= ':' then
  86.   dest = dest || '/'
  87. if dest = '/' then dest = ''
  88.  
  89. dlen = length(dest)
  90.  
  91. bytes = 0
  92. files = 0
  93. dircount = 1
  94.  
  95. say 'Equalize is doing it''s job on 'dest
  96.  
  97. call dolist(dest)
  98.  
  99. say 'Deleted:' files 'files in a total 'dircount' directories.'
  100. say 'This equalization cleared:' bytes 'Bytes.'
  101. say
  102. exit 0
  103.  
  104.  
  105. /* The real thing */
  106.  
  107. dolist: procedure expose files root dest dlen dircount bytes dstat
  108. parse arg x
  109. contents = showdir(x);
  110. do i = 1 to words(contents)
  111.   temp = x || word(contents,i)
  112.   type = statef(temp)
  113.   if word(type,1) = 'FILE' then
  114.     do
  115.         snam = root || right(temp,(length(temp) - dlen))
  116.         if ~ exists(snam) then
  117.         do
  118.                 files = files + 1
  119.                 bytes = bytes + word(type,2)
  120.                 if dstat = 1 then
  121.                 do
  122.                         'delete 'temp
  123.                         say 'Deleted: 'temp
  124.                 end
  125.                 else say 'Would have deleted: 'temp
  126.         end
  127.     end
  128.   if word(type,1) ='DIR' then do
  129.         subdir = root || right(temp,(length(temp) - dlen))
  130.         if ~ exists(subdir) then
  131.           do
  132.                 say 'Subdirectory 'subdir' not found...'
  133.                 if dstat = 1 then
  134.                 do
  135.                         'delete 'temp' all'
  136.                         say 'Removed: 'temp
  137.                 end
  138.                 else say 'Would have removed: 'temp
  139.           end
  140.         call dolist(temp || '/')
  141.         dircount = dircount + 1
  142.   end
  143. end
  144. return
  145.